﻿using System;
using System.Windows.Forms;

namespace idataplatform
{
    public partial class usermanager : Form
    {
        public usermanager()
        {
            InitializeComponent();
        }

        private void usermanager_Load(object sender, EventArgs e)
        {
            conncls conns = new conncls();
            string selSQL = "select ind,uname,case ustatus when 1 then '正常' else '失效' end as ustatus,lltime from users_ipark;";
            dataGridView1.DataSource = conns.Dts(selSQL);
            dataGridView1.ClearSelection();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                conncls conns = new conncls();
                string selSQL = "select ind,uname,case ustatus when 1 then '正常' else '失效' end as ustatus,lltime from users_ipark;";
                conns.sqlexec("UPDATE users_ipark SET ustatus=0 WHERE uname='" + dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[1].Value.ToString() + "';");
                dataGridView1.DataSource = conns.Dts(selSQL);
                dataGridView1.ClearSelection();
                checkBox1.Checked = false;
            }
        }

        private void checkBox1_Click(object sender, EventArgs e)
        {
            conncls conns = new conncls();
            if (checkBox1.Checked == true)
            {
                string selSQL = "select ind,uname,case ustatus when 1 then '正常' end as ustatus,lltime from users_ipark WHERE ustatus=1;";
                dataGridView1.DataSource = conns.Dts(selSQL);
                dataGridView1.ClearSelection();
            }
            else
            {
                string selSQL = "select ind,uname,case ustatus when 1 then '正常' else '失效' end as ustatus,lltime from users_ipark;";
                dataGridView1.DataSource = conns.Dts(selSQL);
                dataGridView1.ClearSelection();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            userdetail form2 = new userdetail("新建用户");
            form2.ShowDialog();
            if (form2.DialogResult == DialogResult.OK)
            {
                conncls conns = new conncls();
                if (checkBox1.Checked == true)
                {
                    string selSQL = "select ind,uname,case ustatus when 1 then '正常' end as ustatus,lltime from users_ipark WHERE ustatus=1;";
                    dataGridView1.DataSource = conns.Dts(selSQL);
                    dataGridView1.ClearSelection();
                    
                }
                else
                {
                    string selSQL = "select ind,uname,case ustatus when 1 then '正常' else '失效' end as ustatus,lltime from users_ipark;";
                    dataGridView1.DataSource = conns.Dts(selSQL);
                    dataGridView1.ClearSelection();
                }
            }
        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                userdetail form2 = new userdetail(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[1].Value.ToString());
                form2.ShowDialog();
                if (form2.DialogResult == DialogResult.OK)
                {
                    conncls conns = new conncls();
                    if (checkBox1.Checked == true)
                    {
                        string selSQL = "select ind,uname,case ustatus when 1 then '正常' end as ustatus,lltime from users_ipark WHERE ustatus=1;";
                        dataGridView1.DataSource = conns.Dts(selSQL);
                        dataGridView1.ClearSelection();
                    }
                    else
                    {
                        string selSQL = "select ind,uname,case ustatus when 1 then '正常' else '失效' end as ustatus,lltime from users_ipark;";
                        dataGridView1.DataSource = conns.Dts(selSQL);
                        dataGridView1.ClearSelection();
                    }
                }
            }
        }
    }
}
